import java.util.Comparator;
import java.util.Set;
import java.util.TreeMap;

public class TreeMapTest {
    public static void main(String[] args) {
        TreeMap<Person,String> t = new TreeMap<>(new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                if(o1.age == o2.age) {
                    return -o1.name.compareTo(o2.name);
                } else {
                    return o1.age - o2.age;
                }

            }
        });
        t.put(new Person("lhangsan",33),"sing");

        t.put(new Person("lisi",18),"dance");
        t.put(new Person("wangwu",18),"rap");
        Set<Person> s = t.keySet();
        for (Person e : s) {
            System.out.println(e+"="+t.get(e));
        }
    }


}
